<template>
  <!-- 短信平台 配置 -->
  <BasicForm @register="register" />
</template>

<script setup lang="ts">
  import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
  import { SMSPlatformConfigSchemas } from './schemas';
  import { useMessage } from '@/hooks/web/useMessage';
  import { inject, Ref } from 'vue';

  const dataId = inject('dataId') as Ref<string | number>;
  const { createMessage } = useMessage();
  const schemas: FormSchema[] = SMSPlatformConfigSchemas();

  const [register, { validate, setProps }] = useForm({
    schemas,
    autoFocusFirstItem: true,
    actionColOptions: {
      span: 24,
    },
    labelWidth: 200,
    submitButtonOptions: {
      text: '保存',
    },
    showResetButton: false,
    submitFunc: async () => {
      try {
        const res = await validate();
        console.log(res, dataId.value);
        setProps({
          submitButtonOptions: {
            loading: true,
          },
        });
        setTimeout(() => {
          setProps({
            submitButtonOptions: {
              loading: false,
            },
          });
          createMessage.success('提交成功！');
        }, 2000);
      } catch (error) {}
    },
  });
</script>

<style scoped></style>
